﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

namespace IpSpy
{
	public class LogManager
	{
		private static string logFileName = ConfigurationManager.AppSettings["Log.FileName"];

		public static void Log(string value)
		{
			lock (typeof(LogManager))
			{
				using (StreamWriter sw = File.Exists(logFileName) ? File.AppendText(logFileName) : new StreamWriter(logFileName))
				{
					sw.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToString().PadRight(19, ' '), value));
				}
			}
		}

		public static void Log(Exception e, string info)
		{
			if (e != null)
			{
				Log(String.Format("{0}: {1}{2}{3}", info, e.Message, Environment.NewLine, e.StackTrace));

				Log(e.InnerException, info);
			}
		}
	}
}
